package com.example.web.controller;

import com.example.frame.annotation.Action;
import com.example.frame.annotation.Autowire;
import com.example.frame.annotation.Controller;
import com.example.frame.bean.Param;
import com.example.frame.bean.View;
import com.example.web.model.Customer;
import com.example.web.service.CustomerService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/** @author chenjiebin */
@Controller
public class CustomerController {

    @Autowire
    private CustomerService customerService;

    @Action("get:/test")
    public View test() {
        String currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        return new View("hello.jsp").addModel("currentTime", currentTime);
    }

    @Action("get:/customer")
    public View getCustomerList(Param param) {
        List<Customer> customerList = customerService.getCustomerList();
        return new View("customer.jsp").addModel("customerList", customerList);
    }

    @Action("get:/customer_show")
    public View show(Param param) {
        long id = param.getLong("id");
        Customer customer = customerService.getCustomer(id);
        return new View("customer_show.jsp").addModel("customer", customer);
    }

}
